<script setup lang="ts">
import { computed } from 'vue'
import { useChatStore } from '@/stores/chat'
import MessageItem from './MessageItem.vue'
import type { Message } from '@/types/chat'

const chatStore = useChatStore()
const messages = computed<Message[]>(() => chatStore.messages)
</script>

<template>
  <div class="message-list-container">
    <div class="message-list">
      <transition-group name="message-fade" tag="div">
        <div v-for="(message, index) in messages" :key="index" class="message-wrapper">
          <MessageItem :message="message" />
        </div>
      </transition-group>
    </div>
  </div>
</template>

<style scoped>
.message-list-container {
  max-height: 70vh;
  overflow-y: auto;
  padding: 16px;
  background-color: #f5f7fa;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-wrapper {
  transition: all 0.3s ease;
}

.message-fade-enter-active,
.message-fade-leave-active {
  transition: opacity 0.5s;
}
.message-fade-enter,
.message-fade-leave-to {
  opacity: 0;
}

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}
</style>
